<template>
    <div class="newsinfo-container">
        <h3 class="title">{{newsInfo.title}}</h3>
        <p class="subtitle">
            <span>发表时间:{{ newsInfo.add_time | dateFormat('YYYY-MM-DD HH:MM:SS') }}</span>
            <span>点击：{{ newsInfo.click }}次</span>
        </p>

        <hr>

        <div class="content" v-html = 'newsInfo.content'></div>
        <!-- 评论子组件区域 -->
        <comment :id='this.id'></comment>
    </div>
</template>

<script>
//导入评论子组件
import comment from '../subcomponents/comment.vue'
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      id: this.$route.params.id, //获取URL地址中传递过来的id值
      newsInfo: {}
    };
  },
  created() {
    this.getNewsInfo();
  },
  methods: {
    getNewsInfo() {
      //获取新闻详情
      // console.log(this.id)
      this.$http.get("api/getnew/" + this.id).then(res => {
        // console.log(res.body);
        if (res.body.status == 0) {
          this.newsInfo = res.body.message[0];
        //   console.log(res.body.message[0]);
        } else {
          Toast("获取新闻详情失败");
        }
      });
    }
  },
  components: {
      //注册评论子组件
      comment
  }
};
</script>

<style lang="scss">
.newsinfo-container {
  padding: 0 4px;
  .title {
    font-size: 16px;
    text-align: center;
    margin: 15px 0;
    color: gold;
  }
  .subtitle {
    font-size: 13px;
    color: #22fa22;
    display: flex;
    justify-content: space-between;
  }
  .content {
      img {
          width: 100%;
      }
  }
}
</style>
